package com.psp.sp.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.northend.util.NumUtil;
import com.psp.sp.controller.res.BaseResult;
import com.psp.sp.controller.res.ListResult;
import com.psp.sp.controller.res.bean.RBillListBean;
import com.psp.sp.controller.springmvc.req.GetBillCashParam;
import com.psp.sp.controller.springmvc.req.GetBillExportParam;
import com.psp.sp.controller.springmvc.req.GetBillListParam;
import com.psp.sp.service.BillService;
import com.psp.sp.service.exception.ServiceException;
import com.psp.sp.service.impl.PageResult;

@Component
public class BillController {

	@Autowired
	BillService billServiceImpl;

	/**
	 * 导出资金账单
	 * 
	 * @param param
	 * @param request
	 * @param response
	 */
	public void export(GetBillExportParam param, HttpServletRequest request, HttpServletResponse response) {

		String uid = "";
		Integer type = param.getType();

		billServiceImpl.export(uid, type);
	}

	/**
	 * 得到资金列表
	 * 
	 * @param param
	 * @param request
	 * @param response
	 * @return
	 */
	public ListResult<RBillListBean> list(GetBillListParam param, HttpServletRequest request,
			HttpServletResponse response) {
		ListResult<RBillListBean> result = new ListResult<>();
		int page = NumUtil.toInt(param.getPage(), 0);
		int pageSize = 10;
		String uid = "";
		int type = NumUtil.toInt(param.getType(), 0);

		PageResult<RBillListBean> resList = billServiceImpl.getList(page, pageSize, uid, type);

		result.setData(resList.getData());
		result.setPage(page);
		result.setTotalSize(resList.getCount());
		result.setToken(param.getToken());

		return result;
	}

	/**
	 * 资金提现
	 * 
	 * @param param
	 * @param request
	 * @param response
	 * @return
	 */
	public BaseResult cash(GetBillCashParam param, HttpServletRequest request, HttpServletResponse response) {
		BaseResult result = new BaseResult();
		try {
			String uid = "";
			boolean flag = billServiceImpl.cash(uid);
			result.setFlag(flag);
		} catch (ServiceException e) {
			result.setServiceException(e);
		}
		result.setToken(param.getToken());
		return result;
	}
}
